package com.naiterui.ehp.bs.payment.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.naiterui.ehp.bs.payment.entity.RefundInfo;
import com.naiterui.ehp.bs.payment.repository.IPayInfoRepository;
import com.naiterui.ehp.bs.payment.repository.IRefundInfoRepository;
import com.naiterui.ehp.bs.payment.service.IOrderStatusService;

import lombok.AllArgsConstructor;

@Service
@AllArgsConstructor
public class OrderStatusServiceImpl implements IOrderStatusService {

    private final IPayInfoRepository payInfoRepository;
    private final IRefundInfoRepository refundInfoRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateRefund(String refundOrderSn, String errCode, String errCodeDes) {
        this.refundInfoRepository.updateStatus(refundOrderSn, RefundInfo.ORDER_STATUS_FAIL, errCode, errCodeDes);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updatePayStatus(String orderSn, Integer notifyBusinessStatus) {
        this.payInfoRepository.updateNotifyBusinessStatus(orderSn, notifyBusinessStatus);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateRefundStatus(String refundOrderSn, Integer notifyBusinessStatus) {
        this.refundInfoRepository.updateNotifyBusinessStatus(refundOrderSn, notifyBusinessStatus);
    }

}
